<?php
/**
 * Created by PhpStorm OF Administrator.
 * User: YUYI
 * Date: 2018/8/8 0008
 * Time: 上午 10:37
 * Administrator
 */

namespace app\api\controller;



use app\common\model\Articles;
use think\db\Query;

class Article extends Base
{
    public function getArticle($id)
    {
        if (!$this->request->isAjax()){
            return $this->errorInfo('非法访问');
        }
        $art = Articles::get($id);
        return $this->successInfo('成功',$art);
    }

    public function getList()
    {
        if (input('mine') == 1){
            $where['userId'] = $this->user->userId;
        }
        $where = isset($where)?$where:null;
        $arts = Articles::all(function (Query $query) use ($where){
            $query->where($where?array_merge(['type'=>10,'status'=>99],$where):['type'=>10,'status'=>99])->order('updateTime desc')->limit(input('size')?:10)->page(input('page'?:1));
        },'user');
        if (!$arts){
            return $this->errorInfo('暂无数据');
        }
        return $this->successInfo('成功',$arts);
    }
}